home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10135 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  856 b 

  1. Path: connix.com!news
  2. From: Scott Hawley <shawley@connix.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Determining the length of an int in string form
  5. Date: Fri, 15 Mar 1996 10:57:26 -0800
  6. Organization: SHAWLEY SYSTEMS
  7. Message-ID: <3149BD96.572@connix.com>
  8. References: <Pine.A32.3.91.960313161835.90740D-100000@red.weeg.uiowa.edu>
  9. NNTP-Posting-Host: shawley.connix.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win16; I)
  14.  
  15. or maybe:
  16.  
  17. int NumLen( int n )
  18. {
  19.     if(n > 9999)return(5);
  20.     if(n > 999)return(4);
  21.     if(n > 99)return(3);
  22.     if(n > 9)return(2);
  23.     return(1);
  24. }
  25.  
  26. or
  27.  
  28. int NumLen( int n)
  29. {
  30.     int digits,ct;
  31.     ct = 9999;
  32.     for(digits = 5; digits > 1; digits--) {
  33.         if(n > ct)break;
  34.         ct - (int)(ct / 10);
  35.     }
  36.     return(digits);
  37. }
  38.  
  39. Just some other thoughts
  40.